#ifndef COORDINATEGRID_H
#define COORDINATEGRID_H
#include<QPoint>
#include<QtOpenGL>
#include<QColor>

#include "coordstransformer.h"

class CoordinateGrid
{
private:
    double _halfWidth;
    double _halfHeight;
    double _centerX;
    double _centerY;
    double _dx;
    double _dy;
    QColor _axisColor;
    QColor _gridLinesColor;

private:
    void _drawAxis();
    void _drawLines();
    void _drawText(QGLWidget *textRenderer);

    double _getTextPosition(double minCoord, double maxCoord);
    double _getTextPositionX(double textWidth);
    double _getTextPositionY(double textHeight);

    QRectF _getTranslatedAlignedBoundingBox();

    QString _createCoordLabel(double coord);

    enum RenderMode { LOGARITHMIC, LINEAR };
    RenderMode _renderMode;



public:
    CoordinateGrid();
    void setBoundingBox(double centerX, double centerY, double width, double heigth);
    void setStep(double dx, double dy);

    void draw(QGLWidget *textRenderer);

    void switchToLogarithmicCoords();
    void switchToLinearCoords();

    double getNearestHumaReadableStep(double number);

    void setAxisColor(QColor color);
    void setGridLinesColor(QColor color);

    double getXCoordFromPoint(double x);
};

#endif // COORDINATEGRID_H
